﻿using System;
using System.Collections.Generic;
using System.Data;

namespace MachineStateOnline.Models
{
    internal struct RetDataPack
    {
        public bool IsGetDataSuccessed;
        public DataTable Table_RunningSpindle;
        public DataTable Table_StopSpindle;
        public DataTable Table_FullSpindle;
        public DataTable Table_AlarmSpindle;

        public RetDataPack(bool item1, DataTable? table_RunningSpindle, DataTable? table_StopSpindle, DataTable? table_FullSpindle, DataTable? table_AlarmSpindle)
        {
            IsGetDataSuccessed = item1;
            Table_RunningSpindle = table_RunningSpindle ?? new DataTable("-1"); 
            Table_StopSpindle = table_StopSpindle ?? new DataTable("-1"); 
            Table_FullSpindle = table_FullSpindle ?? new DataTable("-1"); 
            Table_AlarmSpindle = table_AlarmSpindle ?? new DataTable("-1"); 
        }

        public override bool Equals(object? obj)
        {
            return obj is RetDataPack other &&
                   IsGetDataSuccessed == other.IsGetDataSuccessed &&
                   EqualityComparer<DataTable?>.Default.Equals(Table_RunningSpindle, other.Table_RunningSpindle) &&
                   EqualityComparer<DataTable?>.Default.Equals(Table_StopSpindle, other.Table_StopSpindle) &&
                   EqualityComparer<DataTable?>.Default.Equals(Table_FullSpindle, other.Table_FullSpindle) &&
                   EqualityComparer<DataTable?>.Default.Equals(Table_AlarmSpindle, other.Table_AlarmSpindle);
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(IsGetDataSuccessed, Table_RunningSpindle, Table_StopSpindle, Table_FullSpindle, Table_AlarmSpindle);
        }

        public void Deconstruct(out bool item1, out DataTable? table_RunningSpindle, out DataTable? table_StopSpindle, out DataTable? table_FullSpindle, out DataTable? table_AlarmSpindle)
        {
            item1 = IsGetDataSuccessed;
            table_RunningSpindle = Table_RunningSpindle;
            table_StopSpindle = Table_StopSpindle;
            table_FullSpindle = Table_FullSpindle;
            table_AlarmSpindle = Table_AlarmSpindle;
        }

        public static implicit operator (bool, DataTable? Table_RunningSpindle, DataTable? Table_StopSpindle, DataTable? Table_FullSpindle, DataTable? Table_AlarmSpindle)(RetDataPack value)
        {
            return (value.IsGetDataSuccessed, value.Table_RunningSpindle, value.Table_StopSpindle, value.Table_FullSpindle, value.Table_AlarmSpindle);
        }

        public static implicit operator RetDataPack((bool, DataTable? Table_RunningSpindle, DataTable? Table_StopSpindle, DataTable? Table_FullSpindle, DataTable? Table_AlarmSpindle) value)
        {
            return new RetDataPack(value.Item1, value.Table_RunningSpindle, value.Table_StopSpindle, value.Table_FullSpindle, value.Table_AlarmSpindle);
        }
    }
}

